<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: samples/tapi/hog.cpp</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">samples/tapi/hog.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;fstream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sstream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;iomanip&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;stdexcept&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../da/d74/ocl_8hpp.html">opencv2/core/ocl.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4e/utility_8hpp.html">opencv2/core/utility.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../dc/d3d/videoio_8hpp.html">opencv2/videoio.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d8/da3/objdetect_8hpp.html">opencv2/objdetect.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html">opencv2/imgproc.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d8/dcc/namespacestd.html">std</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"></div><div class="line"><span class="keyword">class </span>App</div><div class="line">{</div><div class="line"><span class="keyword">public</span>:</div><div class="line">    App(<a name="_a0"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">CommandLineParser</a>&amp; cmd);</div><div class="line">    <span class="keywordtype">void</span> run();</div><div class="line">    <span class="keywordtype">void</span> handleKey(<span class="keywordtype">char</span> key);</div><div class="line">    <span class="keywordtype">void</span> hogWorkBegin();</div><div class="line">    <span class="keywordtype">void</span> hogWorkEnd();</div><div class="line">    <span class="keywordtype">string</span> hogWorkFps() <span class="keyword">const</span>;</div><div class="line">    <span class="keywordtype">void</span> workBegin();</div><div class="line">    <span class="keywordtype">void</span> workEnd();</div><div class="line">    <span class="keywordtype">string</span> workFps() <span class="keyword">const</span>;</div><div class="line"><span class="keyword">private</span>:</div><div class="line">    App operator=(App&amp;);</div><div class="line"></div><div class="line">    <span class="comment">//Args args;</span></div><div class="line">    <span class="keywordtype">bool</span> running;</div><div class="line">    <span class="keywordtype">bool</span> make_gray;</div><div class="line">    <span class="keywordtype">double</span> <a name="a1"></a><a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a>;</div><div class="line">    <span class="keywordtype">double</span> resize_scale;</div><div class="line">    <span class="keywordtype">int</span> win_width;</div><div class="line">    <span class="keywordtype">int</span> win_stride_width, win_stride_height;</div><div class="line">    <span class="keywordtype">int</span> gr_threshold;</div><div class="line">    <span class="keywordtype">int</span> nlevels;</div><div class="line">    <span class="keywordtype">double</span> hit_threshold;</div><div class="line">    <span class="keywordtype">bool</span> gamma_corr;</div><div class="line"></div><div class="line">    <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga7cde0074dfd288f2d70c0e035dacb28a">int64</a> hog_work_begin;</div><div class="line">    <span class="keywordtype">double</span> hog_work_fps;</div><div class="line">    <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga7cde0074dfd288f2d70c0e035dacb28a">int64</a> work_begin;</div><div class="line">    <span class="keywordtype">double</span> work_fps;</div><div class="line"></div><div class="line">    <span class="keywordtype">string</span> img_source;</div><div class="line">    <span class="keywordtype">string</span> vdo_source;</div><div class="line">    <span class="keywordtype">string</span> output;</div><div class="line">    <span class="keywordtype">int</span> camera_id;</div><div class="line">    <span class="keywordtype">bool</span> write_once;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)</div><div class="line">{</div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">char</span>* keys =</div><div class="line">        <span class="stringliteral">&quot;{ h help      |                | print help message }&quot;</span></div><div class="line">        <span class="stringliteral">&quot;{ i input     |                | specify input image}&quot;</span></div><div class="line">        <span class="stringliteral">&quot;{ c camera    | -1             | enable camera capturing }&quot;</span></div><div class="line">        <span class="stringliteral">&quot;{ v video     | vtest.avi | use video as input }&quot;</span></div><div class="line">        <span class="stringliteral">&quot;{ g gray      |                | convert image to gray one or not}&quot;</span></div><div class="line">        <span class="stringliteral">&quot;{ s scale     | 1.0            | resize the image before detect}&quot;</span></div><div class="line">        <span class="stringliteral">&quot;{ o output    |   output.avi   | specify output path when input is images}&quot;</span>;</div><div class="line">    <a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">CommandLineParser</a> cmd(argc, argv, keys);</div><div class="line">    <span class="keywordflow">if</span> (cmd.<a name="a2"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a8c41cf242b2ad8c0472e3b57893ef200">has</a>(<span class="stringliteral">&quot;help&quot;</span>))</div><div class="line">    {</div><div class="line">        cmd.<a name="a3"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a84cda3794b765332bfe43bf8367222fb">printMessage</a>();</div><div class="line">        <span class="keywordflow">return</span> EXIT_SUCCESS;</div><div class="line">    }</div><div class="line"></div><div class="line">    App app(cmd);</div><div class="line">    <span class="keywordflow">try</span></div><div class="line">    {</div><div class="line">        app.run();</div><div class="line">    }</div><div class="line">    <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a4"></a><a class="code" href="../../d1/dee/classcv_1_1Exception.html">Exception</a>&amp; e)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">return</span> cout &lt;&lt; <span class="stringliteral">&quot;error: &quot;</span>  &lt;&lt; e.<a name="a5"></a><a class="code" href="../../d1/dee/classcv_1_1Exception.html#a9c1e692401016807255e0e6ad562ece9">what</a>() &lt;&lt; endl, 1;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">catch</span> (<span class="keyword">const</span> exception&amp; e)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">return</span> cout &lt;&lt; <span class="stringliteral">&quot;error: &quot;</span>  &lt;&lt; e.what() &lt;&lt; endl, 1;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">catch</span>(...)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">return</span> cout &lt;&lt; <span class="stringliteral">&quot;unknown exception&quot;</span> &lt;&lt; endl, 1;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> EXIT_SUCCESS;</div><div class="line">}</div><div class="line"></div><div class="line">App::App(<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">CommandLineParser</a>&amp; cmd)</div><div class="line">{</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;\nControls:\n&quot;</span></div><div class="line">         &lt;&lt; <span class="stringliteral">&quot;\tESC - exit\n&quot;</span></div><div class="line">         &lt;&lt; <span class="stringliteral">&quot;\tm - change mode GPU &lt;-&gt; CPU\n&quot;</span></div><div class="line">         &lt;&lt; <span class="stringliteral">&quot;\tg - convert image to gray or not\n&quot;</span></div><div class="line">         &lt;&lt; <span class="stringliteral">&quot;\to - save output image once, or switch on/off video save\n&quot;</span></div><div class="line">         &lt;&lt; <span class="stringliteral">&quot;\t1/q - increase/decrease HOG scale\n&quot;</span></div><div class="line">         &lt;&lt; <span class="stringliteral">&quot;\t2/w - increase/decrease levels count\n&quot;</span></div><div class="line">         &lt;&lt; <span class="stringliteral">&quot;\t3/e - increase/decrease HOG group threshold\n&quot;</span></div><div class="line">         &lt;&lt; <span class="stringliteral">&quot;\t4/r - increase/decrease hit threshold\n&quot;</span></div><div class="line">         &lt;&lt; endl;</div><div class="line"></div><div class="line">    make_gray = cmd.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a8c41cf242b2ad8c0472e3b57893ef200">has</a>(<span class="stringliteral">&quot;gray&quot;</span>);</div><div class="line">    resize_scale = cmd.<a name="a6"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">double</span>&gt;(<span class="stringliteral">&quot;s&quot;</span>);</div><div class="line">    vdo_source = <a name="a7"></a><a class="code" href="../../d6/dba/group__core__utils__samples.html#ga4a37595bcd267558bd6c176c7307f050">samples::findFileOrKeep</a>(cmd.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;v&quot;</span>));</div><div class="line">    img_source = cmd.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;i&quot;</span>);</div><div class="line">    output = cmd.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;o&quot;</span>);</div><div class="line">    camera_id = cmd.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;c&quot;</span>);</div><div class="line"></div><div class="line">    win_width = 48;</div><div class="line">    win_stride_width = 8;</div><div class="line">    win_stride_height = 8;</div><div class="line">    gr_threshold = 8;</div><div class="line">    nlevels = 13;</div><div class="line">    hit_threshold = 1.4;</div><div class="line">    <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a> = 1.05;</div><div class="line">    gamma_corr = <span class="keyword">true</span>;</div><div class="line">    write_once = <span class="keyword">false</span>;</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Group threshold: &quot;</span> &lt;&lt; gr_threshold &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Levels number: &quot;</span> &lt;&lt; nlevels &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Win width: &quot;</span> &lt;&lt; win_width &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Win stride: (&quot;</span> &lt;&lt; win_stride_width &lt;&lt; <span class="stringliteral">&quot;, &quot;</span> &lt;&lt; win_stride_height &lt;&lt; <span class="stringliteral">&quot;)\n&quot;</span>;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Hit threshold: &quot;</span> &lt;&lt; hit_threshold &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Gamma correction: &quot;</span> &lt;&lt; gamma_corr &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; endl;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> App::run()</div><div class="line">{</div><div class="line">    running = <span class="keyword">true</span>;</div><div class="line">    <a name="_a8"></a><a class="code" href="../../dd/d9e/classcv_1_1VideoWriter.html">VideoWriter</a> video_writer;</div><div class="line"></div><div class="line">    <a name="_a9"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> win_size(win_width, win_width * 2);</div><div class="line">    <a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> win_stride(win_stride_width, win_stride_height);</div><div class="line"></div><div class="line">    <span class="comment">// Create HOG descriptors and detectors here</span></div><div class="line"></div><div class="line">    <a name="_a10"></a><a class="code" href="../../d5/d33/structcv_1_1HOGDescriptor.html">HOGDescriptor</a> hog(win_size, <a name="a11"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(16, 16), <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(8, 8), <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(8, 8), 9, 1, -1,</div><div class="line">                          HOGDescriptor::L2Hys, 0.2, gamma_corr, <a name="a12"></a><a class="code" href="../../d5/d33/structcv_1_1HOGDescriptor.html#a039750de6a0c2957d11fbeec84cfc7e1a00a697fa3ad742792128a39785a60ed2">cv::HOGDescriptor::DEFAULT_NLEVELS</a>);</div><div class="line">    hog.<a name="a13"></a><a class="code" href="../../d5/d33/structcv_1_1HOGDescriptor.html#a6de5ac55631eed51e36278cde3a2c159">setSVMDetector</a>( HOGDescriptor::getDaimlerPeopleDetector() );</div><div class="line"></div><div class="line">    <span class="keywordflow">while</span> (running)</div><div class="line">    {</div><div class="line">        <a name="_a14"></a><a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html">VideoCapture</a> vc;</div><div class="line">        <a name="_a15"></a><a class="code" href="../../d7/d45/classcv_1_1UMat.html">UMat</a> frame;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (vdo_source!=<span class="stringliteral">&quot;&quot;</span>)</div><div class="line">        {</div><div class="line">            vc.<a name="a16"></a><a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html#a614a1702e15f42ede5100014ce7f48ed">open</a>(vdo_source.c_str());</div><div class="line">            <span class="keywordflow">if</span> (!vc.<a name="a17"></a><a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html#a9d2ca36789e7fcfe7a7be3b328038585">isOpened</a>())</div><div class="line">                <span class="keywordflow">throw</span> runtime_error(<span class="keywordtype">string</span>(<span class="stringliteral">&quot;can&#39;t open video file: &quot;</span> + vdo_source));</div><div class="line">            vc &gt;&gt; frame;</div><div class="line">        }</div><div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (camera_id != -1)</div><div class="line">        {</div><div class="line">            vc.<a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html#a614a1702e15f42ede5100014ce7f48ed">open</a>(camera_id);</div><div class="line">            <span class="keywordflow">if</span> (!vc.<a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html#a9d2ca36789e7fcfe7a7be3b328038585">isOpened</a>())</div><div class="line">            {</div><div class="line">                stringstream msg;</div><div class="line">                msg &lt;&lt; <span class="stringliteral">&quot;can&#39;t open camera: &quot;</span> &lt;&lt; camera_id;</div><div class="line">                <span class="keywordflow">throw</span> runtime_error(msg.str());</div><div class="line">            }</div><div class="line">            vc &gt;&gt; frame;</div><div class="line">        }</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">        {</div><div class="line">            <a name="a18"></a><a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>(img_source).<a name="a19"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77">copyTo</a>(frame);</div><div class="line">            <span class="keywordflow">if</span> (frame.<a name="a20"></a><a class="code" href="../../d7/d45/classcv_1_1UMat.html#a8d0149f2671fd776444301cafa0eff8c">empty</a>())</div><div class="line">                <span class="keywordflow">throw</span> runtime_error(<span class="keywordtype">string</span>(<span class="stringliteral">&quot;can&#39;t open image file: &quot;</span> + img_source));</div><div class="line">        }</div><div class="line"></div><div class="line">        <a class="code" href="../../d7/d45/classcv_1_1UMat.html">UMat</a> img_aux, img, img_to_show;</div><div class="line"></div><div class="line">        <span class="comment">// Iterate over all frames</span></div><div class="line">        <span class="keywordflow">while</span> (running &amp;&amp; !frame.<a class="code" href="../../d7/d45/classcv_1_1UMat.html#a8d0149f2671fd776444301cafa0eff8c">empty</a>())</div><div class="line">        {</div><div class="line">            workBegin();</div><div class="line"></div><div class="line">            <span class="comment">// Change format of the image</span></div><div class="line">            <span class="keywordflow">if</span> (make_gray) <a name="a21"></a><a class="code" href="../../d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab">cvtColor</a>(frame, img_aux, <a name="a22"></a><a class="code" href="../../d8/d01/group__imgproc__color__conversions.html#gga4e0972be5de079fed4e3a10e24ef5ef0a353a4b8db9040165db4dacb5bcefb6ea">COLOR_BGR2GRAY</a> );</div><div class="line">            <span class="keywordflow">else</span> frame.<a name="a23"></a><a class="code" href="../../d7/d45/classcv_1_1UMat.html#ab9f4b02e099696dc0fb43c85c6f4a2f1">copyTo</a>(img_aux);</div><div class="line"></div><div class="line">            <span class="comment">// Resize image</span></div><div class="line">            <span class="keywordflow">if</span> (<a name="a24"></a><a class="code" href="../../d2/d75/namespacecv.html#af6df65b17fb11af6d34634b6dfa44683">abs</a>(<a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a>-1.0)&gt;0.001)</div><div class="line">            {</div><div class="line">                <a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> sz((<span class="keywordtype">int</span>)((<span class="keywordtype">double</span>)img_aux.<a name="a25"></a><a class="code" href="../../d7/d45/classcv_1_1UMat.html#a18cc40c5ec8a6b95317e5fe6abaca6fc">cols</a>/resize_scale), (<span class="keywordtype">int</span>)((<span class="keywordtype">double</span>)img_aux.<a name="a26"></a><a class="code" href="../../d7/d45/classcv_1_1UMat.html#a8137e5d25233b57db5616f227f1772ee">rows</a>/resize_scale));</div><div class="line">                <a name="a27"></a><a class="code" href="../../d5/df1/group__imgproc__hal__functions.html#ga2fe39d2201b12e1b961ca56b2aff9ff2">resize</a>(img_aux, img, sz, 0, 0, <a name="a28"></a><a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac00f4a8155563cdc23437fc0959da935">INTER_LINEAR_EXACT</a>);</div><div class="line">            }</div><div class="line">            <span class="keywordflow">else</span> img = img_aux;</div><div class="line">            img.<a class="code" href="../../d7/d45/classcv_1_1UMat.html#ab9f4b02e099696dc0fb43c85c6f4a2f1">copyTo</a>(img_to_show);</div><div class="line">            hog.<a name="a29"></a><a class="code" href="../../d5/d33/structcv_1_1HOGDescriptor.html#a94a54b27a5d707796c4fa56766497b5f">nlevels</a> = nlevels;</div><div class="line">            vector&lt;Rect&gt; found;</div><div class="line"></div><div class="line">            <span class="comment">// Perform HOG classification</span></div><div class="line">            hogWorkBegin();</div><div class="line"></div><div class="line">            hog.<a name="a30"></a><a class="code" href="../../d5/d33/structcv_1_1HOGDescriptor.html#a91e56a2c317392e50fbaa2f5dc78d30b">detectMultiScale</a>(img, found, hit_threshold, win_stride,</div><div class="line">                    <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(0, 0), <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a>, gr_threshold);</div><div class="line">            hogWorkEnd();</div><div class="line"></div><div class="line"></div><div class="line">            <span class="comment">// Draw positive classified windows</span></div><div class="line">            <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; found.size(); i++)</div><div class="line">            {</div><div class="line">                <a name="a31"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga07d2f74cadcf8e305e810ce8eed13bc9">rectangle</a>(img_to_show, found[i], <a name="a32"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(0, 255, 0), 3);</div><div class="line">            }</div><div class="line"></div><div class="line">            <a name="a33"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576">putText</a>(img_to_show, <a name="a34"></a><a class="code" href="../../dc/d83/group__core__opencl.html#gadb3b41d4552e9db7887855e3a1b2af37">ocl::useOpenCL</a>() ? <span class="stringliteral">&quot;Mode: OpenCL&quot;</span>  : <span class="stringliteral">&quot;Mode: CPU&quot;</span>, <a name="a35"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">Point</a>(5, 25), <a name="a36"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#gga0f9314ea6e35f99bb23f29567fc16e11afff8b973668df2e4028dddc5274310c9">FONT_HERSHEY_SIMPLEX</a>, 1., <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255, 100, 0), 2);</div><div class="line">            <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576">putText</a>(img_to_show, <span class="stringliteral">&quot;FPS (HOG only): &quot;</span> + hogWorkFps(), <a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">Point</a>(5, 65), <a class="code" href="../../d6/d6e/group__imgproc__draw.html#gga0f9314ea6e35f99bb23f29567fc16e11afff8b973668df2e4028dddc5274310c9">FONT_HERSHEY_SIMPLEX</a>, 1., <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255, 100, 0), 2);</div><div class="line">            <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576">putText</a>(img_to_show, <span class="stringliteral">&quot;FPS (total): &quot;</span> + workFps(), <a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">Point</a>(5, 105), <a class="code" href="../../d6/d6e/group__imgproc__draw.html#gga0f9314ea6e35f99bb23f29567fc16e11afff8b973668df2e4028dddc5274310c9">FONT_HERSHEY_SIMPLEX</a>, 1., <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255, 100, 0), 2);</div><div class="line">            <a name="a37"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;opencv_hog&quot;</span>, img_to_show);</div><div class="line">            <span class="keywordflow">if</span> (vdo_source!=<span class="stringliteral">&quot;&quot;</span> || camera_id!=-1) vc &gt;&gt; frame;</div><div class="line"></div><div class="line">            workEnd();</div><div class="line"></div><div class="line">            <span class="keywordflow">if</span> (output!=<span class="stringliteral">&quot;&quot;</span> &amp;&amp; write_once)</div><div class="line">            {</div><div class="line">                <span class="keywordflow">if</span> (img_source!=<span class="stringliteral">&quot;&quot;</span>)     <span class="comment">// write image</span></div><div class="line">                {</div><div class="line">                    write_once = <span class="keyword">false</span>;</div><div class="line">                    <a name="a38"></a><a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(output, img_to_show);</div><div class="line">                }</div><div class="line">                <span class="keywordflow">else</span>                    <span class="comment">//write video</span></div><div class="line">                {</div><div class="line">                    <span class="keywordflow">if</span> (!video_writer.<a name="a39"></a><a class="code" href="../../dd/d9e/classcv_1_1VideoWriter.html#a9a40803e5f671968ac9efa877c984d75">isOpened</a>())</div><div class="line">                    {</div><div class="line">                        video_writer.<a name="a40"></a><a class="code" href="../../dd/d9e/classcv_1_1VideoWriter.html#a0901c353cd5ea05bba455317dab81130">open</a>(output, VideoWriter::fourcc(<span class="charliteral">&#39;x&#39;</span>,<span class="charliteral">&#39;v&#39;</span>,<span class="charliteral">&#39;i&#39;</span>,<span class="charliteral">&#39;d&#39;</span>), 24,</div><div class="line">                                          img_to_show.<a name="a41"></a><a class="code" href="../../d7/d45/classcv_1_1UMat.html#a762e5567b5c5636f6c1de2c260b12065">size</a>(), <span class="keyword">true</span>);</div><div class="line">                        <span class="keywordflow">if</span> (!video_writer.<a class="code" href="../../dd/d9e/classcv_1_1VideoWriter.html#a9a40803e5f671968ac9efa877c984d75">isOpened</a>())</div><div class="line">                            <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;can&#39;t create video writer&quot;</span>);</div><div class="line">                    }</div><div class="line"></div><div class="line">                    <span class="keywordflow">if</span> (make_gray) <a class="code" href="../../d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab">cvtColor</a>(img_to_show, img, <a name="a42"></a><a class="code" href="../../d8/d01/group__imgproc__color__conversions.html#gga4e0972be5de079fed4e3a10e24ef5ef0a869da65c045477f2f17d39395df65b2d">COLOR_GRAY2BGR</a>);</div><div class="line">                    <span class="keywordflow">else</span> <a class="code" href="../../d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab">cvtColor</a>(img_to_show, img, <a name="a43"></a><a class="code" href="../../d8/d01/group__imgproc__color__conversions.html#gga4e0972be5de079fed4e3a10e24ef5ef0a3a7148dd1537f09d35b69690b0548798">COLOR_BGRA2BGR</a>);</div><div class="line"></div><div class="line">                    video_writer &lt;&lt; img;</div><div class="line">                }</div><div class="line">            }</div><div class="line"></div><div class="line">            handleKey((<span class="keywordtype">char</span>)<a name="a44"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(3));</div><div class="line">        }</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> App::handleKey(<span class="keywordtype">char</span> key)</div><div class="line">{</div><div class="line">    <span class="keywordflow">switch</span> (key)</div><div class="line">    {</div><div class="line">    <span class="keywordflow">case</span> 27:</div><div class="line">        running = <span class="keyword">false</span>;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;m&#39;</span>:</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;M&#39;</span>:</div><div class="line">        <a name="a45"></a><a class="code" href="../../dc/d83/group__core__opencl.html#gab747fa4efd88d3188f4ebcbc8a639c1e">ocl::setUseOpenCL</a>(!<a class="code" href="../../dc/d83/group__core__opencl.html#gadb3b41d4552e9db7887855e3a1b2af37">cv::ocl::useOpenCL</a>());</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Switched to &quot;</span> &lt;&lt; (<a class="code" href="../../dc/d83/group__core__opencl.html#gadb3b41d4552e9db7887855e3a1b2af37">ocl::useOpenCL</a>() ? <span class="stringliteral">&quot;OpenCL enabled&quot;</span> : <span class="stringliteral">&quot;CPU&quot;</span>) &lt;&lt; <span class="stringliteral">&quot; mode\n&quot;</span>;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;g&#39;</span>:</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;G&#39;</span>:</div><div class="line">        make_gray = !make_gray;</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Convert image to gray: &quot;</span> &lt;&lt; (make_gray ? <span class="stringliteral">&quot;YES&quot;</span> : <span class="stringliteral">&quot;NO&quot;</span>) &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;1&#39;</span>:</div><div class="line">        <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a> *= 1.05;</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Scale: &quot;</span> &lt;&lt; <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a> &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;q&#39;</span>:</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;Q&#39;</span>:</div><div class="line">        <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a> /= 1.05;</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Scale: &quot;</span> &lt;&lt; <a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a> &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;2&#39;</span>:</div><div class="line">        nlevels++;</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Levels number: &quot;</span> &lt;&lt; nlevels &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;w&#39;</span>:</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;W&#39;</span>:</div><div class="line">        nlevels = <a name="a46"></a><a class="code" href="../../d7/dcc/group__core__utils__softfloat.html#ga78f988f6cfa6223610298cbd4f86ec66">max</a>(nlevels - 1, 1);</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Levels number: &quot;</span> &lt;&lt; nlevels &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;3&#39;</span>:</div><div class="line">        gr_threshold++;</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Group threshold: &quot;</span> &lt;&lt; gr_threshold &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;e&#39;</span>:</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;E&#39;</span>:</div><div class="line">        gr_threshold = <a class="code" href="../../d7/dcc/group__core__utils__softfloat.html#ga78f988f6cfa6223610298cbd4f86ec66">max</a>(0, gr_threshold - 1);</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Group threshold: &quot;</span> &lt;&lt; gr_threshold &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;4&#39;</span>:</div><div class="line">        hit_threshold+=0.25;</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Hit threshold: &quot;</span> &lt;&lt; hit_threshold &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;r&#39;</span>:</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;R&#39;</span>:</div><div class="line">        hit_threshold = <a class="code" href="../../d7/dcc/group__core__utils__softfloat.html#ga78f988f6cfa6223610298cbd4f86ec66">max</a>(0.0, hit_threshold - 0.25);</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Hit threshold: &quot;</span> &lt;&lt; hit_threshold &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;c&#39;</span>:</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;C&#39;</span>:</div><div class="line">        gamma_corr = !gamma_corr;</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Gamma correction: &quot;</span> &lt;&lt; gamma_corr &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;o&#39;</span>:</div><div class="line">    <span class="keywordflow">case</span> <span class="charliteral">&#39;O&#39;</span>:</div><div class="line">        write_once = !write_once;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">inline</span> <span class="keywordtype">void</span> App::hogWorkBegin()</div><div class="line">{</div><div class="line">    hog_work_begin = <a name="a47"></a><a class="code" href="../../db/de0/group__core__utils.html#gae73f58000611a1af25dd36d496bf4487">getTickCount</a>();</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">inline</span> <span class="keywordtype">void</span> App::hogWorkEnd()</div><div class="line">{</div><div class="line">    <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga7cde0074dfd288f2d70c0e035dacb28a">int64</a> delta = <a class="code" href="../../db/de0/group__core__utils.html#gae73f58000611a1af25dd36d496bf4487">getTickCount</a>() - hog_work_begin;</div><div class="line">    <span class="keywordtype">double</span> freq = <a name="a48"></a><a class="code" href="../../db/de0/group__core__utils.html#ga705441a9ef01f47acdc55d87fbe5090c">getTickFrequency</a>();</div><div class="line">    hog_work_fps = freq / delta;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">inline</span> <span class="keywordtype">string</span> App::hogWorkFps()<span class="keyword"> const</span></div><div class="line"><span class="keyword"></span>{</div><div class="line">    stringstream ss;</div><div class="line">    ss &lt;&lt; hog_work_fps;</div><div class="line">    <span class="keywordflow">return</span> ss.str();</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">inline</span> <span class="keywordtype">void</span> App::workBegin()</div><div class="line">{</div><div class="line">    work_begin = <a class="code" href="../../db/de0/group__core__utils.html#gae73f58000611a1af25dd36d496bf4487">getTickCount</a>();</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">inline</span> <span class="keywordtype">void</span> App::workEnd()</div><div class="line">{</div><div class="line">    <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga7cde0074dfd288f2d70c0e035dacb28a">int64</a> delta = <a class="code" href="../../db/de0/group__core__utils.html#gae73f58000611a1af25dd36d496bf4487">getTickCount</a>() - work_begin;</div><div class="line">    <span class="keywordtype">double</span> freq = <a class="code" href="../../db/de0/group__core__utils.html#ga705441a9ef01f47acdc55d87fbe5090c">getTickFrequency</a>();</div><div class="line">    work_fps = freq / delta;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">inline</span> <span class="keywordtype">string</span> App::workFps()<span class="keyword"> const</span></div><div class="line"><span class="keyword"></span>{</div><div class="line">    stringstream ss;</div><div class="line">    ss &lt;&lt; work_fps;</div><div class="line">    <span class="keywordflow">return</span> ss.str();</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:29 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
